package com.wkck.controller.frontend;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wkck.VO.NewsInfoVO;
import com.wkck.VO.PageResult;
import com.wkck.domain.News;
import com.wkck.dto.NewsQueryBackendDto;
import com.wkck.dto.NewsQueryFrontendDto;
import com.wkck.result.Result;
import com.wkck.service.NewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: CK
 * @Date: 2024/03/23/14:38
 * @Description:
 */
@Api(value = "用户新闻api",tags = "用户新闻api")
@RestController
@RequestMapping("/user/news")
@Slf4j
@CrossOrigin
public class NewsFrontendController {

    @Autowired
    private NewsService newsService;

    /***
     * @Author: CK
     * @Date: 2024/3/21
     * @Param: [dto]
     * @Description: 得到新闻列表数据
     */
    @PostMapping("/get")
    @ApiOperation(value = "得到新闻列表数据")
    public Result<Page<News>> getNewsInfo(@RequestBody NewsQueryFrontendDto dto) {
        log.info("得到新闻列表数据: {}", dto);
        return Result.success(newsService.getFrontendNewsInfo(dto));
    }

    /***
    * @Author: CK
    * @Date: 2024/3/23
    * @Param: [id]
    * @Description: 根据id获得新闻数据
    */
    @GetMapping("/get-news/{id}")
    @ApiOperation(value = "根据id获得新闻数据")
    public Result<NewsInfoVO> getNewsInfoByNewsId(@PathVariable Long id) {
        log.info("根据id获得新闻数据 ====> {}", id);
        return Result.success(newsService.getNewsInfoById(id));
    }
}
